package sugarbind_input

class Article {

    String title
	String pub_Year
	String citation
	String url
	String pm_Id
	Integer article_Import_Ref

    static constraints = {
		title(blank:false)
		pub_Year(nullable:false)
		pm_Id(nullable:true)
		citation(nullable:true)
		url(nullable:true)
		
		article_Import_Ref(nullable:false)
		title(unique:'pub_Year')
		
	}
	
	static hasOne = [article_Type:Article_Type]
	static hasMany = [author_Articles:Author_Article,bindings:Binding]
	static belongsTo = [Binding]
	
	static mapping = {
//		id column: 'article_id'
		id generator: 'sequence', params: [sequence: 'article_id_seq']
		
		bindings joinTable: [name: "binding_article", key: 'article_id']
	}
	
	public String toString(){
		String short_Title = title
		int cutoff = 120
		if(title.length()>cutoff)
		{short_Title = title.substring(0,cutoff) + "..."}
		pub_Year + " / " + short_Title + " ("+id+")" //+ " " + author_Articles.author
	}
	
	public static listArticles()
	{
		Article.list().sort{ it.toString(); }
	}
	
	
		
}
